<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            background: #000;
            text-align: center
        }

        #c1 {
            background: #fff;
        }
    </style>

</head>

<body>
    <canvas id="c1" width="800" height="600">

    </canvas>
</body>
<script>
    let oC = document.getElementById('c1');
    let gd = oC.getContext('2d');       //图形上下文-绘图用的接口
    let cx=100,cy=100,r=50
    //圆形
    // gd.arc(cx,cy,r,0*Math.PI/180,360*Math.PI/180)
    // gd.stroke()
    oC.onmousemove=function (ev){
        let a=ev.offsetX-cx;
        let b=ev.offsetY-cy;
        let dis=Math.sqrt(a*a+b*b);
        gd.clearRect(0,0,800,600);
        gd.arc(cx,cy,r,0,2*Math.PI,true)
        if(dis<r){
            gd.fillStyle='red'
        }else{
            gd.fillStyle='yellow'
        }
        gd.fill()
        
    }
</script>

</html>